/* CSE 142 Winter 2008, Marty Stepp This program reads an input file of data about students' attendance in section and outputs the attendance, points earned, and grade percentages for each student in each section. The format of the input file is explained in the Ch. 7 lecture slides. Example line of input from the file, sections.txt: 111111101011111101001110110110110001110010100 Example output for the above line: Sections attended: [9, 6, 7, 4, 3] Student scores: [20, 18, 20, 12, 9] Student grades: [100.0, 90.0, 100.0, 60.0, 45.0] */ import java.io.*; // for File import java.util.*; // for Scanner public class Sections { public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(new File("sections.txt")); while (input.hasNextLine()) { int[] students = new int[5]; String line = input.nextLine(); // compute each student's sections attended for (int i = 0; i < line.length(); i++) { char c = line.charAt(i); if (c == '1') { // student went to class! // string "111111101011111101001110110110110001110010100" // index 01234567890123456789 // student 012340123401234 students[i % 5]++; } } System.out.println("Sections attended: " + Arrays.toString(students)); // compute each student's points earned int[] scores = new int[5]; for (int i = 0; i < students.length; i++) { scores[i] = Math.min(20, students[i] * 3); } System.out.println("Scores: " + Arrays.toString(scores)); } } }